package com.boarsoft.boar.batch.demo.flow.demo;

import com.boarsoft.boar.batch.bean.BatchExecCtrlFlag;
import com.boarsoft.boar.batch.demo.entity.EmpSalary;
import com.boarsoft.boar.batch.service.BatchReportService;
import com.boarsoft.common.util.InetUtil;
import com.boarsoft.flow.core.bean.ProcessHandler;
import com.boarsoft.hibernate.biz.SimpleBizImpl;
import com.boarsoft.hibernate.dao.SimpleDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 根据条件，查询符合涨薪条件的员工数
 *
 * @author tao.wang57
 * @date 2023-12-20
 */
public class DemoProcess1HD extends SimpleBizImpl implements ProcessHandler {

    @Autowired
    private BatchReportService batchReportService;

    @Autowired
    private SimpleDao simpleDao;

    @Override
    public Object process(String entry, Object data, Throwable throwable) throws Throwable {
        //TODO 判断当前执行类型 （新跑、重跑、续跑）
        short exeType = BatchExecCtrlFlag.getExeType("123456");
        //TODO 判断当前执行状态
        short exeStatus = BatchExecCtrlFlag.getStatus("123456");

        System.out.println(" do DemoProcess1HD...");
        /**
         * 此处为模拟查询总数
         */
        String hql = " from EmpSalary where 1=1 order by id";
        List<EmpSalary> empList = simpleDao.list(hql);
        /*
        for (EmpSalary emp : empList) {
            System.out.println("id=" + emp.getId() + ", name = " + emp.getName() + ", salary=" + emp.getSalary());
        }
         */

        /**
         * 批量执行上报
         * 直接上报该阶段完成后作业的执行进度为5%，此接口入参均为必输
         */
//        batchReportService.report("123456", "+5", "DemoProcess1HD", InetUtil.getIp());
        return empList;
    }
}
